<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.brooklynmarathon.checkout.Customer" %>
<%@ page import="com.brooklynmarathon.checkout.PMF" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>

<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with Customers you post.</p>
<%
    }
%>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Customer.class.getName() + " order by date desc range 0,5";
    List<Customer> Customers = (List<Customer>) pm.newQuery(query).execute();
    if (Customers.isEmpty()) {
%>
<p>The com.brooklynmarathon.checkout has no messages.</p>
<%
    } else {
        for (Customer g : Customers) {
            if (g.getAuthor() == null) {
%>
<p>An anonymous person wrote:</p>
<%
            } else {
%>
<p><b><%= g.getAuthor().getNickname() %></b> wrote:</p>
<%
            }
%>
<blockquote><%= g.getContent() %> XML: <%=g.getXmlResponse()%> TransactionId: <%=g.getTransactionId()%></blockquote>
<%
        }
    }
    pm.close();
%>

    <form action="/CustomerSingleUseToken" method="post">
      <div><textarea name="content" rows="3" cols="60"></textarea></div>
      <div><input type="text" name="amount"/></div>
      <div><input type="text" name="reason"/></div>
      <div><input type="text" name="rec_token" value="R16EPESTQ6FBQ5N4GQ6I65YG9Y4EILM55T4MXBZ71PVKJSKHL2ZLUJNQ7PWHY6I5"/></div>
      <!-- <div><input type="text" name="rec_token" value="M2LD42KZJR5CCGGE33EH3DRD4HFEKBI3NGLK124TAHVLAMA9NQQ7KESGNNTHQRQT"/></div> -->
      <div><input type="submit" value="Sign up" /></div>
    </form>

  </body>
</html>
